﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PI_CS_Library.PicsNetwork_Information_Model;
using PI_CS_Library.Virtual_Network_Information_Model;
using PI_CS_Library;

namespace PI_CS_GUI
{
    public partial class VirtualLinkGUI : Form
    {
        int EDGE = 367;
        GUIDelegate _gui;
        Dictionary<int, Link> _linkList;
        int _capacity;
        int _used;
        int _vnId;

        public VirtualLinkGUI(int _srcId, int _dstId, int _vnId, PicsNetwork _network, GUIDelegate _gui)
        {
            InitializeComponent();
            label1.Text = _network.GetVirtualNetwork(_vnId).GetMatrix(_srcId).Name + " -> " + _network.GetVirtualNetwork(_vnId).GetMatrix(_dstId).Name;
            label1.Location = new Point(EDGE - label1.Size.Width, label1.Location.Y);
            this._vnId = _vnId;
            _linkList = new Dictionary<int, Link>();

            foreach(Link l in _network.GetVirtualNetwork(_vnId).LinkList.Values)
            {
                if (l.SrcMatrix.Id.Number == _srcId && l.SinkMatrix.Id.Number == _dstId)
                {
                    listBox1.Items.Add(l.Id.Number);
                    _linkList.Add(l.Id.Number, l);
                    _capacity += l.Parameters.Capacity;
                    _used += l.Parameters.Capacity - l.Parameters.AvailableCapacity;
                }
            }

            label5.Text = Convert.ToString(_capacity);
            progressBar1.Minimum = 0;
            progressBar1.Maximum = 100;
            progressBar1.Value = (int)(((double)_used / (double)_capacity) * 100);

            this._gui = _gui;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int _id = (int)(listBox1.SelectedItem);
            Link _currLink = _linkList[_id];
            _gui(null, new GUIArgs("showVirtualLink#" + listBox1.SelectedItem));
            groupBox1.Enabled = true;
            label10.Text = Convert.ToString(_currLink.Parameters.Capacity);
            label11.Text = Convert.ToString(_currLink.Parameters.AvailableCapacity);
            label12.Text = Convert.ToString(_currLink.Parameters.Delay);
            label13.Text = Convert.ToString(_currLink.Parameters.ErrorRate);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //foreach (Link l in _linkList.Values)
            //    _gui(null, new GUIArgs("showVirtualLink#" + l.Id.Number + "#" + _vnId));
            this.Close();
        }


    }
}
